#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QDateTime>
#include <QMainWindow>
#include "classes/aithread.h"
#include "classes/model.h"
#include "historydialog.h"
#include "serverssettingsdialog.h"

namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
    void loadComboBoxModelPicker(int index);
    void adjustPushButtonSend();
    void saveHistory();
    void loadHistory(const QString& historyPath);
    void clear(bool saveHistory);
    bool isClean();
    
    void record(const QString& question, const QString& answer, bool saveHistory);
    void readListItem(int index);

    bool getLocalModelList(QStringList& localModelList);
    
    void askQuestion(const QString& question);
    void freeAIThread();
    
    void loadServerConfig(QStringList& serverUrlList);

    void slot_showHistory(const ChatHistory& chatHistory, int index);
    void slot_updateOutputArea(const QString& originalQuestion, const QString& answer);
    void slot_record(const QString& question, const QString& answer);
    
    void slot_updateServersSettings();

signals:
    void signal_freeSubThreads();

private slots:
    void on_actionNewChat_triggered();
    void on_actionHistory_triggered();
    void on_actionQuit_triggered();
    void on_pushButtonSend_clicked();
    void on_listWidgetQuestions_currentRowChanged(int currentRow);
    void on_pushButtonLocker_clicked();
    void on_pushButtonStop_clicked();
    void on_pushButtonDisplayNewestChat_clicked();
    void on_comboBoxModelTypePicker_currentIndexChanged(int index);
    void on_actionServersSettings_triggered();
    
    void on_textEditInputArea_textChanged();
    
private:
    QStringList questionList;
    QStringList answerList;
    
    Ui::MainWindow *ui = nullptr;
    HistoryDialog *historyDialog = nullptr;
    ServersSettingsDialog *serversSettingsDialog = nullptr;
    
    QString historyDir = "./history";
    QString dateStr = "";
    AIThread* aiThread = nullptr;
    Model* model = nullptr;
    
    QStringList jsonList;
    QStringList keysList;
};
#endif // MAINWINDOW_H
